object work {
	println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet


	def from(x: Int): Stream[Int] = x #:: from(x + 1)
                                                  //> from: (x: Int)Stream[Int]

	from(0).take(5).foreach(x=> print(x + ","))
                                                  //> 0,1,2,3,4,
	
	def fib: Stream[Int] = {
		def f(x: Int, y: Int): Stream[Int] = (x + y) #:: f(y, x + y)
		 0 #:: f(0, 1)
	}                                         //> fib: => Stream[Int]
	fib.take(10).foreach(x=> print(x + ","))  //> 0,1,2,3,5,8,13,21,34,55,
	
	
	def fib2(x: Int, y: Int): Stream[Int] = (x + y) #:: fib2(y, x + y)
                                                  //> fib2: (x: Int, y: Int)Stream[Int]
	fib2(1,2).take(10).foreach(x=>print(x+","))
                                                  //> 3,5,8,13,21,34,55,89,144,233,
	def ronda1(x: Int): Stream[Int] = (x) #:: ronda1(if (x >= 0) -x-1 else -x)
                                                  //> ronda1: (x: Int)Stream[Int]
	ronda1(0).take(15).foreach(x=>print(x + ","))
                                                  //> 0,-1,1,-2,2,-3,3,-4,4,-5,5,-6,6,-7,7,


	def ronda(c:Int, x: Int): Stream[Int] = (c+x) #:: ronda(c, if (x >= 0) -x-1 else -x)
                                                  //> ronda: (c: Int, x: Int)Stream[Int]
	ronda(10, 0).take(15).foreach(x=>print(x + ","))
                                                  //> 10,9,11,8,12,7,13,6,14,5,15,4,16,3,17,
                                                  
	ronda(10, 0).take(15).foreach(x=>print(x + ","))
	
		
}